import {
  fangtuceng,
  gcqytuceng,
  getTuLiByData,
  mapAndCenter,
  removehighlightLayer,
  sztpinkzhi,
  xhqytuceng
} from '@/utils/map/mapTools3x'
import { useClearMap } from '@/hooks/useClearMap'

/**
 * 城市跳转
 * @param name
 */
export const useToVideoTab = (name) => {
  if (name.includes('石家庄') || name.includes('辛集')) {
    window.open('javascript:window.name;', '<script>location.replace("' + 'https://10.0.20.1:1443/ssoforicm/login?userCode=shijiazhuangguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do' + '")<\/script>')
    // window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=shijiazhuangguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener');
  } else if (name.includes('承德')) {
    /* window.open('javascript:window.name;',
      '<script>location.replace("'+'https://10.0.20.1:1443/ssoforicm/login?userCode=chengdeguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank'+'")<\/script>');*/
    window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=chengdeguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  } else if (name.includes('张家口')) {
    window.open('javascript:window.name;', '<script>location.replace("' + 'https://10.0.20.1:1443/ssoforicm/login?userCode=zhangjiakouguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do' + '")<\/script>')
    // window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=zhangjiakouguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  } else if (name.includes('秦皇岛')) {
    window.open('javascript:window.name;', '<script>location.replace("' + 'https://10.0.20.1:1443/ssoforicm/login?userCode=qhdguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do' + '")<\/script>')
    // window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=qhdguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  } else if (name.includes('唐山')) {
    window.open('javascript:window.name;', '<script>location.replace("' + 'https://10.0.20.1:1443/ssoforicm/login?userCode=tangshanguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do' + '")<\/script>')
    // window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=tangshanguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  } else if (name.includes('廊坊')) {
    /* window.open('javascript:window.name;',
      '<script>location.replace("'+'https://10.0.20.1:1443/ssoforicm/login?userCode=langfangguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank'+'")<\/script>');*/
    window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=langfangguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  } else if (name.includes('保定')) {
    window.open('javascript:window.name;', '<script>location.replace("' + 'https://10.0.20.1:1443/ssoforicm/login?userCode=baodingguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do' + '")<\/script>')
    // window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=baodingguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  } else if (name.includes('沧州')) {
    window.open('javascript:window.name;', '<script>location.replace("' + 'https://10.0.20.1:1443/ssoforicm/login?userCode=cangzhouguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do' + '")<\/script>')
    // window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=cangzhouguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  } else if (name.includes('邯郸')) {
    window.open('javascript:window.name;', '<script>location.replace("' + 'https://10.0.20.1:1443/ssoforicm/login?userCode=handanguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do' + '")<\/script>')
    // window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=handanguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  } else if (name.includes('雄安新区')) {
    window.open('javascript:window.name;', '<script>location.replace("' + 'https://10.0.20.1:1443/ssoforicm/login?userCode=xionganguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do' + '")<\/script>')
    // window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=xionganguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  } else if (name.includes('衡水')) {
    window.open('javascript:window.name;', '<script>location.replace("' + 'https://10.0.20.1:1443/ssoforicm/login?userCode=hengshuiguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do' + '")<\/script>')
    // window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=hengshuiguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  } else if (name.includes('邢台')) {
    window.open('javascript:window.name;', '<script>location.replace("' + 'https://10.0.20.1:1443/ssoforicm/login?userCode=xingtaiguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do' + '")<\/script>')
    // window.open('https://10.0.20.1:1443/ssoforicm/login?userCode=xingtaiguokongshuizhan&pwd=35614a8758a2e3bf5258a759c9f325377f077539a85c4f39abc12bb7e38cc3b5&service=https://10.0.20.1:1443/bvideo-web/index.do', '_blank', 'noopener')
  }
}

/**
 * 节点按下
 * @param e
 */
export const useHandleRemove = (e) => {
  const dialogHeaderEl = document.getElementsByClassName('yidonghover')[0]
  const dragDom = document.getElementsByClassName('heliupups')[0]
  dialogHeaderEl.style.cssText += ';cursor:move;'
  // 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
  const sty = (function() {
    if (window.document.currentStyle) {
      return (dom, attr) => dom.currentStyle[attr]
    } else {
      return (dom, attr) => getComputedStyle(dom, false)[attr]
    }
  })()
  dialogHeaderEl.onmousedown = (e) => {
    // 鼠标按下，计算当前元素距离可视区的距离
    const disX = e.clientX - dialogHeaderEl.offsetLeft
    const disY = e.clientY - dialogHeaderEl.offsetTop

    const screenWidth = document.body.clientWidth // body当前宽度
    const screenHeight = document.documentElement.clientHeight // 可见区域高度(应为body高度，可某些环境下无法获取)
    const kuan = dragDom.offsetWidth
    const gao = dragDom.offsetHeight

    const dragDomWidth = dragDom.offsetWidth // 对话框宽度
    const dragDomheight = dragDom.offsetHeight // 对话框高度
    const minDragDomLeft = dragDom.offsetLeft
    const maxDragDomLeft = screenWidth - dragDom.offsetLeft - dragDomWidth

    const minDragDomTop = dragDom.offsetTop
    const maxDragDomTop = screenHeight - dragDom.offsetTop - dragDomheight

    // 获取到的值带px 正则匹配替换
    let styL = sty(dragDom, 'left')
    let styT = sty(dragDom, 'top')

    // 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
    if (styL.includes('%')) {
      styL = +document.body.clientWidth * (+styL.replace(/\%/g, '') / 100)
      styT = +document.body.clientHeight * (+styT.replace(/\%/g, '') / 100)
    } else {
      styL = +styL.replace(/\px/g, '')
      styT = +styT.replace(/\px/g, '')
    }
    document.onmousemove = function(e) {
      // 通过事件委托，计算移动的距离
      let left = e.clientX - disX
      let top = e.clientY - disY

      // 边界处理
      if (-(left) > minDragDomLeft) {
        left = -(minDragDomLeft)
      } else if (left > maxDragDomLeft) {
        left = maxDragDomLeft
      }
      // if(left>screenWidth){
      //   left=maxDragDomLeft-kuan
      // }
      if (-(top) > minDragDomTop) {
        top = -(minDragDomTop)
      } else if (top > maxDragDomTop) {
        top = maxDragDomTop
      }
      // if(top>dragDomheight){
      //   top=maxDragDomTop-50
      // }
      // 移动当前元素
      dragDom.style.cssText += `;left:${left + styL}px;top:${top + styT}px;`
    }
    document.onmouseup = function(e) {
      document.onmousemove = null
      document.onmouseup = null
    }
  }
}

/**
 * 默认调用所有类型的接口 - 点击河流树状图的时候调用
 * @param self
 * @param dt
 * @param params
 * @param map
 * @returns {Promise<void>}
 */
export const useHandlesBlurAll = async(self, dt, params, map) => {
  const resTuli = []
  self.bdListOpt.forEach(map => {
    const info = self.rhhlMapTuli.find(s => s.label === map)
    if (info) {
      resTuli.push(info)
    }
  })
  self.mapTuLi = resTuli
  if (dt && dt == 'dt') {
    // mapAndCenter(Number(params.lon), Number(params.lat), this.map, 10.23)
    self.changeMpaCenter(params)
  } else {
    // mapAndCenter(119.670046, 39.734952, this.map, 10.23)
  }
  self.clearmrparame('bdh')
  self.clearWry()
  useClearMap('cz', map)
  self.layout.showLoading()
  if (self.bdListOptTotal.includes('自动站')) {
    await self.bdh_zdz()
  }
  if (self.bdListOptTotal.includes('工业企业')) {
    await self.bdh_gy()
  }
  if (self.bdListOptTotal.includes('污水处理厂')) {
    await self.bdh_jz()
  }
  if (self.bdListOptTotal.includes('规上畜禽养殖')) {
    await self.bdh_xq1()
  }
  if (self.bdListOptTotal.includes('规下畜禽养殖')) {
    await self.bdh_xq2()
  }
  if (self.bdListOptTotal.includes('水产养殖')) {
    await self.bdh_sc()
  }
  if (self.bdListOptTotal.includes('入河排污口')) {
    await self.bdh_pk()
  }
  if (self.bdListOptTotal.includes('傍河村庄')) {
    await self.bdh_cz()
  }
  if (self.bdListOptTotal.includes('入海排污口')) {
    await self.bdh_rhpwk()
  }
  if (self.bdListOptTotal.includes('涉海风险源')) {
    await self.bdh_shfxy()
  }
  if (self.bdListOptTotal.includes('地表水断面')) {
    await self.getxinshijian()
  }
  self.bdztqkCount = self.bdztqkNum.reduce((total, item) => total + item.num, 0)
  self.layout.hideLoading()
}

/**
 * 地图恢复
 * @param self
 */
export const useRestoreDefault = (self) => {
  const stationActive = self.stationActive
  // 创建鼠标点击事件
  const clickEvent = new MouseEvent('click', {
    bubbles: true, cancelable: true, view: window
  })
  if (stationActive === 0) { // 地表水
    // 将this.stationActive 设置为null后使组件v-if判断失败，页面更新后再重新将 this.stationActive 赋值会之前的值实现页面回到最初的状态
    self.stationActive = null
    self.$nextTick(() => {
      self.stationActive = stationActive
      // js模拟鼠标点击事件
      self.$refs.centerMenu0[0].dispatchEvent(clickEvent)
    })
  } else if (stationActive === 1 && false) { // 饮用水
    // 将this.stationActive 设置为null后使组件v-if判断失败，页面更新后再重新将 this.stationActive 赋值会之前的值实现页面回到最初的状态
    self.stationActive = null
    self.$nextTick(() => {
      self.stationActive = stationActive
      // js模拟鼠标点击事件
      self.$refs.centerMenu1[0].dispatchEvent(clickEvent)
    })
  } else if (stationActive === 2) { // 排污口
    // 将this.stationActive 设置为null后使组件v-if判断失败，页面更新后再重新将 this.stationActive 赋值会之前的值实现页面回到最初的状态
    self.stationActive = null
    self.$nextTick(() => {
      self.stationActive = stationActive
      // js模拟鼠标点击事件
      self.$refs.centerMenu2[0].dispatchEvent(clickEvent)
    })
  } else if (stationActive === 3) { // 污染源
    // 将this.stationActive 设置为null后使组件v-if判断失败，页面更新后再重新将 this.stationActive 赋值会之前的值实现页面回到最初的状态
    self.stationActive = null
    self.$nextTick(() => {
      self.stationActive = stationActive
      // js模拟鼠标点击事件
      self.$refs.centerMenu3[0].dispatchEvent(clickEvent)
    })
  } else if (stationActive === 4) { // 美丽海湾
    // 将this.stationActive 设置为null后使组件v-if判断失败，页面更新后再重新将 this.stationActive 赋值会之前的值实现页面回到最初的状态
    self.stationActive = null
    self.$nextTick(() => {
      self.stationActive = stationActive
      // js模拟鼠标点击事件
      self.$refs.centerMenu4[0].dispatchEvent(clickEvent)
    })
  } else if (stationActive === 7) { // 污水厂
    // 将this.stationActive 设置为null后使组件v-if判断失败，页面更新后再重新将 this.stationActive 赋值会之前的值实现页面回到最初的状态
    self.stationActive = null
    self.$nextTick(() => {
      self.stationActive = stationActive
      // js模拟鼠标点击事件
      self.$refs.centerMenu7[0].dispatchEvent(clickEvent)
    })
  }
}

/**
 * 清空左侧河流树状图
 * @param self 组件实例
 * @param map 地图实例
 */
export const useQingkongtree = (self, map) => {
  // 设置树状图默认选中为空
  self.currentnode = ''
  // 如果树状图存在，设置选中为空
  if (self.$refs.treezujian) {
    self.$refs.treezujian.setCurrentKey(null)
  }
  // 设置河流输入框为空
  self.xlvalue = ''
  // 清空河流选中状态和河流弹窗
  sztpinkzhi('', map)
  self.changeCenter()
}

/**
 * 点击入河排污口选项内容 - 定位高亮
 * @param rhpwk
 * @param self
 * @param map
 */
export const clickRhpwkTabsItems = (rhpwk, self, map) => {
  if (rhpwk.isActive) {
    rhpwk.isActive = false
    self.$store.commit('commonData/SET_RHPWK_ITEM', '')
  } else {
    self.rhpwkData.forEach(rhpwk => {
      rhpwk.isActive = false
    })
    rhpwk.isActive = true
    self.$store.commit('commonData/SET_RHPWK_ITEM', rhpwk)
  }
  self.bdhRhpwkName !== rhpwk.pwkmc ? self.bdhRhpwkName = rhpwk.pwkmc : self.bdhRhpwkName = ''
  if (self.bdhRhpwkName && self.bdhRhpwkName !== '') {
    const params = {
      lon: self.$store.state.commonData.rhpwkItem.lon || self.$store.state.commonData.rhpwkItem.longitude,
      lat: self.$store.state.commonData.rhpwkItem.lat || self.$store.state.commonData.rhpwkItem.latitude,
      map,
      zoom: 20.23
    }
    if (self.bdType === 'rhpwk' && self.stationActive === 3) {
      self.mapCheckListChange_rhpwk('dt', params)
    }
  } else {
    if (self.bdType === 'rhpwk' && self.stationActive === 3) {
      self.mapCheckListChange_rhpwk()
    }
  }
}

/**
 * 初始化默认展示 入海河流风险感知数据
 * @param type tabs类型 => type.name === 1 水质风险感知 type.name === 0 入海河流水质
 * @param self 组件实例
 * @param map 地图实例
 */
export const useInitChangebdhxx = (type, self, map) => {
  self.layout.showLoading()
  mapAndCenter(119.41010268430291, 39.74080657918234, map, 10.23)
  self.BDxuans = type.name
  // console.log('type.name', type.name)
  self.tcView2 = false
  self.tcView3 = false
  self.tcView4 = false
  self.clearmrparame('bdh')
  self.clearWry()
  useClearMap('', map)
  removehighlightLayer(map)
  if (type.name == 0) {
    self.currentnode = null
    self.xlvalue = ''
    // this.bdListOpt=['工业企业','污水处理厂','污水泵站','规上畜禽养殖','规下畜禽养殖','水产养殖','傍河村庄','入河排污口','入海排污口','涉海风险源']
    self.bdListOpt = ['地表水断面'] // 默认选择地表水断面
    self.bdslist = []
    self.getRiverCityCount('bdh')
    self.getsWryCountList()
    self.bdh_zdz()
    self.bdh_gy()
    self.bdh_jz()
    self.bdh_xq1()
    self.bdh_xq2()
    self.bdh_sc()
    self.bdh_pk()
    self.bdh_cz()
    self.bdh_rhpwk()
    // 地表水断面
    self.getxinshijian()
    self.loadxxzhi(false)
    if (fangtuceng != null) {
      fangtuceng.setVisible(false)
    }
    if (xhqytuceng != null) {
      xhqytuceng.setVisible(false)
    }
    if (gcqytuceng != null) {
      gcqytuceng.setVisible(false)
    }
    const resTuli = []
    self.bdListOpt.forEach(map => {
      const info = self.rhhlMapTuli.find(s => s.label === map)
      if (info) {
        resTuli.push(info)
      }
    })
    self.mapTuLi = resTuli
    self.DBSType = 'bsdh'
  } else if (type.name === 1) {
    self.layout.showLoading()
    // this.loadxxzhi(true)
    if (fangtuceng != null) {
      fangtuceng.setVisible(false)
    }
    if (xhqytuceng != null) {
      xhqytuceng.setVisible(false)
    }
    if (gcqytuceng != null) {
      gcqytuceng.setVisible(false)
    }
    self.mapTuLi = getTuLiByData('GIS')
    self.DBSType = 'bdh_szhzd'
    self.layout.hideLoading()
  } else {
    self.loadxxzhi(true)
    if (fangtuceng != null) {
      fangtuceng.setVisible(true)
    }
    if (xhqytuceng != null) {
      xhqytuceng.setVisible(true)
    }
    if (gcqytuceng != null) {
      gcqytuceng.setVisible(true)
    }
    self.mapTuLi = getTuLiByData('GIS')
    self.DBSType = 'bdh'
  }
}

/**
 * 入海河流 - 水质风险感知 - 复选框勾选 - 点位渲染函数
 * @param dt
 * @param params
 * @param self
 * @param map
 * @returns {Promise<void>}
 */
export const useHandlesBlur = async(dt, params, self, map) => {
  const resTuli = []
  self.bdListOpt.forEach(map => {
    const info = self.rhhlMapTuli.find(s => s.label === map)
    if (info) {
      resTuli.push(info)
    }
  })
  self.mapTuLi = resTuli
  if (dt && dt === 'dt') {
    // mapAndCenter(Number(params.lon), Number(params.lat), map, 10.23)
    self.changeMpaCenter(params)
  } else {
    // mapAndCenter(119.670046, 39.734952, map, 10.23)
  }
  self.clearmrparame('bdh')
  self.clearWry()
  useClearMap('cz', map)
  self.layout.showLoading()
  if (self.bdListOpt.includes('自动站')) {
    await self.bdh_zdz()
  }
  if (self.bdListOpt.includes('工业企业')) {
    await self.bdh_gy()
  }
  if (self.bdListOpt.includes('污水处理厂')) {
    await self.bdh_jz()
  }
  if (self.bdListOpt.includes('规上畜禽养殖')) {
    await self.bdh_xq1()
  }
  if (self.bdListOpt.includes('规下畜禽养殖')) {
    await self.bdh_xq2()
  }
  if (self.bdListOpt.includes('水产养殖')) {
    await self.bdh_sc()
  }
  if (self.bdListOpt.includes('入河排污口')) {
    await self.bdh_pk()
  }
  if (self.bdListOpt.includes('傍河村庄')) {
    await self.bdh_cz()
  }
  if (self.bdListOpt.includes('入海排污口')) {
    await self.bdh_rhpwk()
  }
  if (self.bdListOpt.includes('涉海风险源')) {
    await self.bdh_shfxy()
  }
  if (self.bdListOpt.includes('地表水断面')) {
    await self.getxinshijian()
  }
  self.bdztqkCount = self.bdztqkNum.reduce((total, item) => total + item.num, 0)
  self.layout.hideLoading()
}

/**
 * 近岸海域 - 复选框勾选 - 点位渲染函数
 * @param dt
 * @param params
 * @param self
 * @param map
 */
export const useHandlesBdhJahyBlur = async(dt, params, self, map) => {
  if (dt && dt === 'dt') {
    mapAndCenter(Number(params.lon), Number(params.lat), map, 10.23)
    self.changeMpaCenter(params)
  } else {
    mapAndCenter(119.41010268430291, 39.74080657918234, map, 10.23)
  }
  self.clearmrparame('bdh')
  self.clearWry()
  useClearMap('cz', map)
  if (self.bdh_jahy_ListOpt.includes('海水浴场')) {
    await self.bdh_jahy_hsyc()
  }
  if (self.bdh_jahy_ListOpt.includes('近岸水质')) {
    await self.bdh_jahy_jahy()
  }
  if (self.bdh_jahy_ListOpt.includes('浴场外围海域')) {
    await self.bdh_jahy_ycwwhy()
  }
  if (self.bdh_jahy_ListOpt.includes('秦皇岛港海域')) {
    await self.bdh_jahy_qhdghy()
  }
  if (self.bdh_jahy_ListOpt.includes('重点河口海域')) {
    await self.bdh_jahy_zdhkhy()
  }
}

/**
 * 设置水质风险感知图例
 * @param {设置水质风险感知图例} data
 */
export const useSetSzfxgzTuli = (data) => {
  const tuLi = []
  data.forEach(item => {
    item = item.toString()
    switch (item) {
      case '11':
      case '12':
      case '13':
        tuLi.push(
          { label: '地表水断面', value: require('../assets/images/dbsIcons/sk2.png') }
        )
        break
      case '2':
        tuLi.push(
          { label: '水质自动站', value: require('../assets/images/dbsIcons/gkcz.png') }
        )
        break
      case '31':
      case '32':
      case '33':
        tuLi.push(
          { label: '污水处理厂', value: require('../assets/images/dbsIcons/gk22.png') }
        )
        break
      case '10':
        tuLi.push(
          { label: '污水泵站', value: require('../assets/images/dbsIcons/gkcz6.png') }
        )
        break
      case '41':
      case '42':
      case '43':
      case '44':
      case '45':
      case '46':
        tuLi.push(
          { label: '涉水工业企业', value: require('../assets/images/dbsIcons/gk11.png') }
        )
        break
      case '5':
        tuLi.push(
          { label: '规上畜禽养殖', value: require('../assets/images/dbsIcons/gk33.png') }
        )
        break
      case '6':
        tuLi.push(
          { label: '规下畜禽养殖', value: require('../assets/images/dbsIcons/gk44.png') }
        )
        break
      case '7':
        tuLi.push(
          { label: '水产养殖', value: require('../assets/images/dbsIcons/gk55.png') }
        )
        break
      case '8':
        tuLi.push(
          { label: '傍河村庄', value: require('../assets/images/dbsIcons/gk77.png') }
        )
        break
      case '91':
      case '92':
      case '93':
      case '94':
        tuLi.push(
          { label: '入河排污口', value: require('../assets/images/dbsIcons/gk66.png') }
        )
        break
      case '101':
        tuLi.push(
          { label: '入海排污口', value: require('../assets/images/dbsIcons/gk6.png') }
        )
        break
      case '111':
        tuLi.push(
          { label: '涉海风险源', value: require('../assets/images/dbsIcons/gkcz2.png') }
        )
        break
    }
  })
  // 根据 label 属性进行去重
  return tuLi.filter((obj, index, self) =>
    index === self.findIndex((o) => o.label === obj.label)
  )
}

/**
 *  在数组中的索引。如果两者都存在
 *  并且 'remoteSensing' 的索引小于 'topographicMap' 的索引
 *  就使用 splice 方法从数组中移除 'remoteSensing'
 * @param arr
 * @author 赵京涛
 */
export const useResolveMappingConflict = (arr) => {
  // 复制数组以避免直接修改原数组
  const filtered = [...arr]
  const indexOfRemoteSensing = filtered.indexOf('remoteSensing')
  const indexOfTopographicMap = filtered.indexOf('topographicMap')
  // 如果 remoteSensing 和 topographicMap 都存在
  if (indexOfRemoteSensing !== -1 && indexOfTopographicMap !== -1) {
    // 保留两者中索引较大的那个元素，移除另一个
    if (indexOfRemoteSensing < indexOfTopographicMap) {
      filtered.splice(indexOfRemoteSensing, 1)
    } else {
      filtered.splice(indexOfTopographicMap, 1)
    }
  }
  return filtered
}
